import { type PropType } from 'vue';

export type OperationButton = {
  type: 'primary' | 'success' | 'warning' | 'danger' | 'info';
  size: 'small' | 'default' | 'large';
  plain: boolean;
  icon: string;
  label: string;
  link: boolean;
  class: string;
  visiable: boolean;
};

export const defaultButton: OperationButton = {
  type: 'primary',
  size: 'small',
  plain: true,
  icon: '',
  label: '',
  link: false,
  class: '',
  visiable: true,
};

export type ButtonType =
  | 'add'
  | 'del'
  | 'edit'
  | 'save'
  | 'copy'
  | 'addExpand';

export type Buttons = (
  | 'add'
  | 'del'
  | 'edit'
  | 'save'
  | 'copy'
  | 'addExpand'
)[];

export const defaultButtons = [
  'edit',
  'save',
  'add',
  'copy',
  'del',
  'addExpand',
];

export const defaultButtonNames = {
  add: '添加',
  del: '删除',
  edit: '编辑',
  save: '保存',
  copy: '复制',
  addExpand: '添加子元素',
};

const defaultButtonConfig = (config: Partial<OperationButton>) =>
  Object.assign({}, defaultButton, config);

export const props = {
  width: {
    type: [String, Number] as PropType<string | number>,
    default: '',
  },
  label: {
    type: String,
    default: '',
  },
  prop: {
    type: String,
    default: '',
  },
  type: {
    type: String as PropType<
      'index' | 'selection' | 'expand' | undefined
    >,
    default: undefined,
  },
  operation: {
    type: Boolean,
    default: false,
  },
  buttons: {
    type: Array as PropType<Buttons>,
    default: () => defaultButtons,
  },
  add: {
    type: Object as PropType<Partial<OperationButton>>,
    default: defaultButtonConfig({ label: '增加', visiable: false }),
  },
  del: {
    type: Object as PropType<Partial<OperationButton>>,
    default: defaultButtonConfig({ label: '删除', type: 'danger' }),
  },
  edit: {
    type: Object as PropType<Partial<OperationButton>>,
    default: defaultButtonConfig({ label: '编辑' }),
  },
  save: {
    type: Object as PropType<Partial<OperationButton>>,
    default: defaultButtonConfig({ label: '保存', type: 'success' }),
  },
  copy: {
    type: Object as PropType<Partial<OperationButton>>,
    default: defaultButtonConfig({ label: '复制' }),
  },
  addExpand: {
    type: Object as PropType<Partial<OperationButton>>,
    default: defaultButtonConfig({ label: '添加子元素' }),
  },
};
